package com.hry.store.cms.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hry.store.cms.dao.SecondCategoryMapper;
import com.hry.store.cms.pojo.SecondCategory;
import com.hry.store.cms.service.SecondCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SecondCategoryServiceImpl implements SecondCategoryService {

    @Autowired
    private SecondCategoryMapper secondCategoryMapper;
    /**
     * 根据一级分类Id查询二级标题
     * @param topCategoryId
     * @return
     */
    @Override
    public List<SecondCategory> getByTopCategory(Integer topCategoryId) {

        return secondCategoryMapper.selectByTopCategoryId(topCategoryId);
    }

    /**
     * 添加二级标题
     * @param topCategory
     * @param productName
     * @return
     */
    @Override
    public int addSecondCategory(Integer topCategory, String productName) {
        SecondCategory secondCategory = new SecondCategory();
        secondCategory.setTopCategoryId(topCategory);
        secondCategory.setSecondCategoryName(productName);
        secondCategory.setStatus(1);
        return secondCategoryMapper.insertSelective(secondCategory);
    }

    /**
     * 查询所有商品
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo getAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SecondCategory> secondCategoryList = secondCategoryMapper.getAll();
        PageInfo pageInfo = new PageInfo(secondCategoryList);
        return pageInfo;
    }

    /**
     * 添加商品到分类表中
     * @param secondCategoryId
     * @param prodcutDesc
     */
    @Override

    public void addProductDescBySecondCategoryId(Integer secondCategoryId, String prodcutDesc) {
        SecondCategory secondCategory = new SecondCategory();
        secondCategory.setSecondCategoryId(secondCategoryId);
        secondCategory.setIsStartProduct(0);
        secondCategory.setIsHotProduct(0);
        secondCategory.setProductDesc(prodcutDesc);
        secondCategoryMapper.updateByPrimaryKeySelective(secondCategory);
    }
}
